
/*
 * Copyright (C) Igor Sysoev
 * Copyright (C) Nginx, Inc.
 */


#ifndef _NGX_HTTP_REQUEST_H_INCLUDED_
#define _NGX_HTTP_REQUEST_H_INCLUDED_


#define NGX_HTTP_MAX_URI_CHANGES           10
#define NGX_HTTP_MAX_SUBREQUESTS           200

/* must be 2^n */
#define NGX_HTTP_LC_HEADER_LEN             32


#define NGX_HTTP_DISCARD_BUFFER_SIZE       4096
#define NGX_HTTP_LINGERING_BUFFER_SIZE     4096


#define NGX_HTTP_VERSION_9                 9
#define NGX_HTTP_VERSION_10                1000
#define NGX_HTTP_VERSION_11                1001

#define NGX_HTTP_UNKNOWN                   0x0001
#define NGX_HTTP_GET                       0x0002
#define NGX_HTTP_HEAD                      0x0004
#define NGX_HTTP_POST                      0x0008
#define NGX_HTTP_PUT                       0x0010
#define NGX_HTTP_DELETE                    0x0020
#define NGX_HTTP_MKCOL                     0x0040
#define NGX_HTTP_COPY                      0x0080
#define NGX_HTTP_MOVE                      0x0100
#define NGX_HTTP_OPTIONS                   0x0200
#define NGX_HTTP_PROPFIND                  0x0400
#define NGX_HTTP_PROPPATCH                 0x0800
#define NGX_HTTP_LOCK                      0x1000
#define NGX_HTTP_UNLOCK                    0x2000
#define NGX_HTTP_PATCH                     0x4000
#define NGX_HTTP_TRACE                     0x8000

#define NGX_HTTP_CONNECTION_CLOSE          1
#define NGX_HTTP_CONNECTION_KEEP_ALIVE     2


#define NGX_NONE                           1


#define NGX_HTTP_PARSE_HEADER_DONE         1

#define NGX_HTTP_CLIENT_ERROR              10
#define NGX_HTTP_PARSE_INVALID_METHOD      10
#define NGX_HTTP_PARSE_INVALID_REQUEST     11
#define NGX_HTTP_PARSE_INVALID_09_METHOD   12

#define NGX_HTTP_PARSE_INVALID_HEADER      13


/* unused                                  1 */
#define NGX_HTTP_SUBREQUEST_IN_MEMORY      2
#define NGX_HTTP_SUBREQUEST_WAITED         4
#define NGX_HTTP_LOG_UNSAFE                8


#define NGX_HTTP_CONTINUE                  100
#define NGX_HTTP_SWITCHING_PROTOCOLS       101
#define NGX_HTTP_PROCESSING                102

#define NGX_HTTP_OK                        200
#define NGX_HTTP_CREATED                   201
#define NGX_HTTP_ACCEPTED                  202
#define NGX_HTTP_NO_CONTENT                204
#define NGX_HTTP_PARTIAL_CONTENT           206

#define NGX_HTTP_SPECIAL_RESPONSE          300
#define NGX_HTTP_MOVED_PERMANENTLY         301
#define NGX_HTTP_MOVED_TEMPORARILY         302
#define NGX_HTTP_SEE_OTHER                 303
#define NGX_HTTP_NOT_MODIFIED              304
#define NGX_HTTP_TEMPORARY_REDIRECT        307

#define NGX_HTTP_BAD_REQUEST               400
#define NGX_HTTP_UNAUTHORIZED              401
#define NGX_HTTP_FORBIDDEN                 403
#define NGX_HTTP_NOT_FOUND                 404
#define NGX_HTTP_NOT_ALLOWED               405
#define NGX_HTTP_REQUEST_TIME_OUT          408
#define NGX_HTTP_CONFLICT                  409
#define NGX_HTTP_LENGTH_REQUIRED           411
#define NGX_HTTP_PRECONDITION_FAILED       412
#define NGX_HTTP_REQUEST_ENTITY_TOO_LARGE  413
#define NGX_HTTP_REQUEST_URI_TOO_LARGE     414
#define NGX_HTTP_UNSUPPORTED_MEDIA_TYPE    415
#define NGX_HTTP_RANGE_NOT_SATISFIABLE     416


/* Our own HTTP codes */

/* The special code to close connection without any response */
#define NGX_HTTP_CLOSE                     444

#define NGX_HTTP_NGINX_CODES               494

#define NGX_HTTP_REQUEST_HEADER_TOO_LARGE  494

#define NGX_HTTPS_CERT_ERROR               495
#define NGX_HTTPS_NO_CERT                  496

/*
 * We use the special code for the plain HTTP requests that are sent to
 * HTTPS port to distinguish it from 4XX in an error page redirection
 */
#define NGX_HTTP_TO_HTTPS                  497

/* 498 is the canceled code for the requests with invalid host name */

/*
 * HTTP does not define the code for the case when a client closed
 * the connection while we are processing its request so we introduce
 * own code to log such situation when a client has closed the connection
 * before we even try to send the HTTP header to it
 */
#define NGX_HTTP_CLIENT_CLOSED_REQUEST     499


#define NGX_HTTP_INTERNAL_SERVER_ERROR     500
#define NGX_HTTP_NOT_IMPLEMENTED           501
#define NGX_HTTP_BAD_GATEWAY               502
#define NGX_HTTP_SERVICE_UNAVAILABLE       503
#define NGX_HTTP_GATEWAY_TIME_OUT          504
#define NGX_HTTP_INSUFFICIENT_STORAGE      507


#define NGX_HTTP_LOWLEVEL_BUFFERED         0xf0
#define NGX_HTTP_WRITE_BUFFERED            0x10
#define NGX_HTTP_GZIP_BUFFERED             0x20
#define NGX_HTTP_SSI_BUFFERED              0x01
#define NGX_HTTP_SUB_BUFFERED              0x02
#define NGX_HTTP_COPY_BUFFERED             0x04


typedef enum {
    NGX_HTTP_INITING_REQUEST_STATE = 0,
    NGX_HTTP_READING_REQUEST_STATE, //fzc: 进行到ngx_http_create_request时被设置
    NGX_HTTP_PROCESS_REQUEST_STATE, //fzc: 在ngx_http_process_request_headers中检测到读取并解析完头部时设置

    NGX_HTTP_CONNECT_UPSTREAM_STATE,
    NGX_HTTP_WRITING_UPSTREAM_STATE,
    NGX_HTTP_READING_UPSTREAM_STATE,

    NGX_HTTP_WRITING_REQUEST_STATE, //fzc: 在ngx_http_finalize_request中某些分支中在调用的ngx_http_set_write_handler内部设置
    NGX_HTTP_LINGERING_CLOSE_STATE,
    NGX_HTTP_KEEPALIVE_STATE //fzc: 在ngx_http_finalize_request中判断出要keepalive的分支中调用的ngx_http_set_keepalive内部设置
} ngx_http_state_e;


typedef struct {
    ngx_str_t                         name;
    ngx_uint_t                        offset;
    ngx_http_header_handler_pt        handler;
} ngx_http_header_t;


typedef struct {
    ngx_str_t                         name;
    ngx_uint_t                        offset;
} ngx_http_header_out_t;


typedef struct {
    ngx_list_t                        headers; //fzc: 元素为ngx_table_elt_t

    ngx_table_elt_t                  *host;
    ngx_table_elt_t                  *connection;
    ngx_table_elt_t                  *if_modified_since;
    ngx_table_elt_t                  *if_unmodified_since;
    ngx_table_elt_t                  *if_match;
    ngx_table_elt_t                  *if_none_match;
    ngx_table_elt_t                  *user_agent;
    ngx_table_elt_t                  *referer;
    ngx_table_elt_t                  *content_length;
    ngx_table_elt_t                  *content_type;

    ngx_table_elt_t                  *range;
    ngx_table_elt_t                  *if_range;

    ngx_table_elt_t                  *transfer_encoding;
    ngx_table_elt_t                  *expect;
    ngx_table_elt_t                  *upgrade;

#if (NGX_HTTP_GZIP)
    ngx_table_elt_t                  *accept_encoding;
    ngx_table_elt_t                  *via;
#endif

    ngx_table_elt_t                  *authorization;

    ngx_table_elt_t                  *keep_alive;

#if (NGX_HTTP_X_FORWARDED_FOR)
    ngx_array_t                       x_forwarded_for;
#endif

#if (NGX_HTTP_REALIP)
    ngx_table_elt_t                  *x_real_ip;
#endif

#if (NGX_HTTP_HEADERS)
    ngx_table_elt_t                  *accept;
    ngx_table_elt_t                  *accept_language;
#endif

#if (NGX_HTTP_DAV)
    ngx_table_elt_t                  *depth;
    ngx_table_elt_t                  *destination;
    ngx_table_elt_t                  *overwrite;
    ngx_table_elt_t                  *date;
#endif

    ngx_str_t                         user;
    ngx_str_t                         passwd;

    ngx_array_t                       cookies;

    ngx_str_t                         server;
    off_t                             content_length_n;
    time_t                            keep_alive_n;

    unsigned                          connection_type:2; //fzc: 解析头部Connection, 值为NGX_HTTP_CONNECTION_KEEP_ALIVE或NGX_HTTP_CONNECTION_CLOSE
    unsigned                          chunked:1;
    unsigned                          msie:1;
    unsigned                          msie6:1;
    unsigned                          opera:1;
    unsigned                          gecko:1;
    unsigned                          chrome:1;
    unsigned                          safari:1;
    unsigned                          konqueror:1;
} ngx_http_headers_in_t;


typedef struct {
    ngx_list_t                        headers;

    ngx_uint_t                        status;
    ngx_str_t                         status_line;

    ngx_table_elt_t                  *server;
    ngx_table_elt_t                  *date;
    ngx_table_elt_t                  *content_length;
    ngx_table_elt_t                  *content_encoding;
    ngx_table_elt_t                  *location;
    ngx_table_elt_t                  *refresh;
    ngx_table_elt_t                  *last_modified;
    ngx_table_elt_t                  *content_range;
    ngx_table_elt_t                  *accept_ranges;
    ngx_table_elt_t                  *www_authenticate;
    ngx_table_elt_t                  *expires;
    ngx_table_elt_t                  *etag;

    ngx_str_t                        *override_charset;

    size_t                            content_type_len;
    ngx_str_t                         content_type;
    ngx_str_t                         charset;
    u_char                           *content_type_lowcase;
    ngx_uint_t                        content_type_hash;

    ngx_array_t                       cache_control;

    off_t                             content_length_n;
    time_t                            date_time;
    time_t                            last_modified_time;
} ngx_http_headers_out_t;


typedef void (*ngx_http_client_body_handler_pt)(ngx_http_request_t *r);

typedef struct {
    ngx_temp_file_t                  *temp_file; //fzc: 存在http包体的临时文件
    ngx_chain_t                      *bufs; //fzc: 接收http包体的缓冲区链表
    ngx_buf_t                        *buf; //fzc: 直接接收http包体的缓冲
    off_t                             rest; //fzc: 根据content-length头部和已经接收到的包体长度, 计算出的还需要接收的包体长度
    ngx_chain_t                      *free;
    ngx_chain_t                      *busy;
    ngx_http_chunked_t               *chunked;
    ngx_http_client_body_handler_pt   post_handler; //fzc: 接收完包体后执行的回调, 其实就是ngx_http_read_client_request_body方法的第二个参数
} ngx_http_request_body_t;


typedef struct ngx_http_addr_conf_s  ngx_http_addr_conf_t;

typedef struct {
    ngx_http_addr_conf_t             *addr_conf;
    ngx_http_conf_ctx_t              *conf_ctx;

#if (NGX_HTTP_SSL && defined SSL_CTRL_SET_TLSEXT_HOSTNAME)
    ngx_str_t                        *ssl_servername;
#if (NGX_PCRE)
    ngx_http_regex_t                 *ssl_servername_regex;
#endif
#endif

    ngx_buf_t                       **busy;
    ngx_int_t                         nbusy;

    ngx_buf_t                       **free;
    ngx_int_t                         nfree;

#if (NGX_HTTP_SSL)
    unsigned                          ssl:1;
#endif
    unsigned                          proxy_protocol:1;
} ngx_http_connection_t;


typedef void (*ngx_http_cleanup_pt)(void *data);

typedef struct ngx_http_cleanup_s  ngx_http_cleanup_t;

struct ngx_http_cleanup_s {
    ngx_http_cleanup_pt               handler;
    void                             *data;
    ngx_http_cleanup_t               *next;
};


typedef ngx_int_t (*ngx_http_post_subrequest_pt)(ngx_http_request_t *r,
    void *data, ngx_int_t rc);

typedef struct {
    ngx_http_post_subrequest_pt       handler;
    void                             *data;
} ngx_http_post_subrequest_t; //fzc: 子请求结束时的回调, 设置到子请求的r->post_subrequest


typedef struct ngx_http_postponed_request_s  ngx_http_postponed_request_t;

struct ngx_http_postponed_request_s {
    ngx_http_request_t               *request;
    ngx_chain_t                      *out; //fzc: 当前子请求的接受到的响应数据
    ngx_http_postponed_request_t     *next; //fzc: 下一个子请求
};


typedef struct ngx_http_posted_request_s  ngx_http_posted_request_t;

struct ngx_http_posted_request_s {
    ngx_http_request_t               *request;
    ngx_http_posted_request_t        *next;
};


typedef ngx_int_t (*ngx_http_handler_pt)(ngx_http_request_t *r);
typedef void (*ngx_http_event_handler_pt)(ngx_http_request_t *r); //fzc: http协议, 事件发生时的回调, 注意返回值类型为void


struct ngx_http_request_s {
    uint32_t                          signature;         /* "HTTP" */ //fzc: 在赋值为NGX_HTTP_MODULE

    ngx_connection_t                 *connection; //fzc: 指向对应的ngx_connection_s

    void                            **ctx; //fzc: 留给http模块设置其请求级别的上下文, 见ngx_http_set_ctx, 注意仅仅提供给http模块, 空间限制, 见ngx_http_create_request
    void                            **main_conf; //fzc: 分别对应ngx_http_connection_t中的conf_ctx结构体成员
    void                            **srv_conf;
    void                            **loc_conf;

    ngx_http_event_handler_pt         read_event_handler; //fzc: 当接收完http请求数据, 第一次从业务层面来处理http请求时, 会调用ngx_http_process_request, 内部会把rev->handler和write->handler都设置为ngx_http_request_handler, 相当于在tcp层不区分读写, 只要有事件发生就调用ngx_http_request_handler, 而在ngx_http_request_handler内部又重新根据读写事件判断使用read_event_handler还是write_event_handler来处理, 即在http层区分读写事件. 和ev->handler一样, 一个回调函数正常完成工作说明该阶段工作完成, 需要在退出前设置新的read/write_event_handler以保证下一个阶段的工作能通过回调执行到.
    ngx_http_event_handler_pt         write_event_handler;

#if (NGX_HTTP_CACHE)
    ngx_http_cache_t                 *cache;
#endif

    ngx_http_upstream_t              *upstream;
    ngx_array_t                      *upstream_states; //fzc:? 用途?
                                         /* of ngx_http_upstream_state_t */

    ngx_pool_t                       *pool; //fzc: 该请求相关的内存池, 会在ngx_http_free_request中被销毁, 与ngx_connection_s中的pool内存池意义不同, 该请求释放了, 不代表tcp连接关闭.
    ngx_buf_t                        *header_in; //fzc: 未处理的客户端数据, 在ngx_http_create_request中被赋值为c->buffer或hc->busy[0]

    ngx_http_headers_in_t             headers_in; //fzc: headers_in->headers在ngx_http_process_request_line时初始化
    ngx_http_headers_out_t            headers_out; //fzc: headers_out->headers在ngx_http_create_request内初始化, http模块把响应信息放到headers_out中, 最后http框架会将它的成员序列化成http响应包发给客户端

    ngx_http_request_body_t          *request_body; //fzc: 接收http请求中的包体数据的结构体

    time_t                            lingering_time; //fzc: 延迟关闭的时间
    time_t                            start_sec; //fzc: http请求启动的时间, 在ngx_http_create_request中被赋值
    ngx_msec_t                        start_msec;

    ngx_uint_t                        method; //fzc: 以下9个成员都是在ngx_http_process_request_line方法接收, 解析http请求行时解析出的信息
    ngx_uint_t                        http_version; //fzc: 在ngx_http_parse_request_line被赋值

    ngx_str_t                         request_line; //fzc: 在ngx_http_process_request_line中解析出http request line后赋值到这个字段
    ngx_str_t                         uri;
    ngx_str_t                         args;
    ngx_str_t                         exten;
    ngx_str_t                         unparsed_uri;

    ngx_str_t                         method_name; //fzc: 同样是在ngx_http_process_request_line中被赋值
    ngx_str_t                         http_protocol; //fzc: 同上

    ngx_chain_t                      *out; //fzc: 要发给客户端的http响应, 会保存由headers_out序列化后的http响应头, 已经调用ngx_http_output_filter方法后保存的http包体, 是实现异步发送http响应的关键！
    ngx_http_request_t               *main; //fzc: 原始请求, 通常用main比较当前请求, 如果相等, 表示当前是原始请求, 否则为子请求
    ngx_http_request_t               *parent; //fzc: 当前请求的父请求
    ngx_http_postponed_request_t     *postponed; //fzc: 多个子请求的响应的链表, 给postpone_filter模块使用来组合响应
    ngx_http_post_subrequest_t       *post_subrequest; //fzc: 子请求结束回调, 只有子请求有, 原始请求不会被调用该成员
    ngx_http_posted_request_t        *posted_requests; //fzc: 子请求链表, ngx_http_run_posted_requests就是通过遍历该链表来执行所有的子请求 

    ngx_int_t                         phase_handler; //fzc: 指出当前http请求应该执行的phase_engine中的ngx_http_phase_handler_t数组的哪个handler, 注意phase_handler是在ngx_http_process_request->ngx_http_handler中被初始化为0
    ngx_http_handler_pt               content_handler; //fzc: 在ngx_http_update_location_config中被赋值为clcf->handler, clcf->handler是http模块在NGX_HTTP_CONTENT_PHASE处理阶段提供给http模块处理请求的另一种方式, 与把处理方法设置到cmcf->phase_handler不一样, 前者可以特定于某类请求, 而不是所有请求, 更灵活更有针对性, 因此很多http模块都喜欢使用前者的策略来实现http请求的处理工作, 这里的content_handler只是为了方便使用clcf->handler, 减少寻找clcf的步骤.
    ngx_uint_t                        access_code; //fzc: 在NGX_HTTP_ACCESS_PHASE处理阶段需要判断请求是否具有访问权限时, 通过access_code来传递http模块的handler回调的返回值, 如果access_code为0, 则表示请求具备访问权限, 反之则说明请求不具备访问权限.

    ngx_http_variable_value_t        *variables; //fzc: 在ngx_http_create_request初始化

#if (NGX_PCRE)
    ngx_uint_t                        ncaptures;
    int                              *captures;
    u_char                           *captures_data;
#endif

    size_t                            limit_rate;
    size_t                            limit_rate_after;

    /* used to learn the Apache compatible response length without a header */
    size_t                            header_size;

    off_t                             request_length; //fzc: http请求的全部长度, 包括http包体

    ngx_uint_t                        err_status;

    ngx_http_connection_t            *http_connection; //fzc: 指向该请求对应的ngx_http_connection_s, 在ngx_http_init_connection中构造
#if (NGX_HTTP_SPDY)
    ngx_http_spdy_stream_t           *spdy_stream;
#endif

    ngx_http_log_handler_pt           log_handler;

    ngx_http_cleanup_t               *cleanup; //fzc: 如果在该请求中打开了某些资源, 并需要在请求结束时释放, 那么就需要把定义的释放资源方法添加到cleanup成员中.

    unsigned                          subrequests:8; //fzc: 表示当前可用的subrequest个数, 在ngx_http_create_request中被赋值为NGX_HTTP_MAX_SUBREQUESTS+1, 即当前最多只能有NGX_HTTP_MAX_SUBREQUESTS个子请求
    unsigned                          count:8; //fzc: 表示该请求的引用次数, 在使用subrequest功能时, 依附在这个请求上的子请求数目会返回到count上, 每增加一个子请求, count数就会加1, 其中任何一个子请求派生出新的子请求时, 对应的原始请求(main指针指向的请求)的count数也要加1. 又如接收http包体时, 由于这是一个异步调用, 因此count也需要加1, 这样在结束请求时, 就不会因为count引用计数未清零时销毁请求. 
    unsigned                          blocked:8; //fzc: 阻塞标志位, 仅aio使用

    unsigned                          aio:1; //fzc: 为1时标识当前请求正在使用异步文件io

    unsigned                          http_state:4; //fzc: 表示http的处理阶段, 跳转到ngx_http_state_e即可见所有枚举状态

    /* URI with "/." and on Win32 with "//" */
    unsigned                          complex_uri:1;

    /* URI with "%" */
    unsigned                          quoted_uri:1;

    /* URI with "+" */
    unsigned                          plus_in_uri:1;

    /* URI with " " */
    unsigned                          space_in_uri:1;

    unsigned                          invalid_header:1; //fzc: 在ngx_http_parse_header_line中用作标记该header是否合法

    unsigned                          add_uri_to_alias:1;
    unsigned                          valid_location:1;
    unsigned                          valid_unparsed_uri:1;
    unsigned                          uri_changed:1; //fzc: 为1时标识当前请求发生过rewrite重写
    unsigned                          uri_changes:4; //fzc: 表示rewrite重写的次数, 最多10次, 因此uri_changes会初始化11, 每rewrite一次就减1, 减到0就直接返回, 在ngx_http_create_request中赋值为NGX_HTTP_MAX_URI_CHANGES+1, 在ngx_http_core_post_rewrite_phase中减1.

    unsigned                          request_body_in_single_buf:1; //fzc: 等于clcf->client_body_in_single_buffer
    unsigned                          request_body_in_file_only:1; //fzc: 以下五个都关联clcf->client_body_in_file_only
    unsigned                          request_body_in_persistent_file:1;
    unsigned                          request_body_in_clean_file:1;
    unsigned                          request_body_file_group_access:1;
    unsigned                          request_body_file_log_level:3;

    unsigned                          subrequest_in_memory:1; //fzc: 为1时表示不转发上游响应, 为1时则转发, 然后看u->buffering来决定是使用固定大小内存还是使用更多的内存和磁盘文件来缓存响应
    unsigned                          waited:1;

#if (NGX_HTTP_CACHE)
    unsigned                          cached:1;
#endif

#if (NGX_HTTP_GZIP)
    unsigned                          gzip_tested:1;
    unsigned                          gzip_ok:1;
    unsigned                          gzip_vary:1;
#endif

    unsigned                          proxy:1;
    unsigned                          bypass_cache:1;
    unsigned                          no_cache:1;

    /*
     * instead of using the request context data in
     * ngx_http_limit_conn_module and ngx_http_limit_req_module
     * we use the single bits in the request structure
     */
    unsigned                          limit_conn_set:1;
    unsigned                          limit_req_set:1;

#if 0
    unsigned                          cacheable:1;
#endif

    unsigned                          pipeline:1;
    unsigned                          chunked:1;
    unsigned                          header_only:1; //fzc: 为1时表示只发送头部, 有多种情况会设置该标识, 如在ngx_http_header_filter中检查到method为HEAD则置位header_only
    unsigned                          keepalive:1; //fzc: 为1时表示是keepalive请求
    unsigned                          lingering_close:1; //fzc: 为1时表示需要延迟关闭, 在接收完包头时如果发现包体存在, 会设置lingering_close为1, 如果放弃接收包体又会设置为0
    unsigned                          discard_body:1; //fzc: 为1时表示正在丢弃http请求中的包体
    unsigned                          internal:1; //fzc: 为1时表示请求的当前状态是在做内部跳转, 和clcf->internal不同但相关联, 后者仅表示当前location是否只用在内部请求的跳转, 已知前者在ngx_http_named_location,ngx_http_internal_redirect,ngx_http_subrequest三个方法中被置位
    unsigned                          error_page:1;
    unsigned                          ignore_content_encoding:1;
    unsigned                          filter_finalize:1;
    unsigned                          post_action:1;
    unsigned                          request_complete:1;
    unsigned                          request_output:1;
    unsigned                          header_sent:1; //fzc: 为1时表示响应头部已经发送, 防止重复发送, ngx_http_send_header中调用ngx_http_top_header_filter全局回调链, 该链中会调用header_filter过滤模块(倒数第二个过滤模块), 其中会将header_sent置位
    unsigned                          expect_tested:1;
    unsigned                          root_tested:1;
    unsigned                          done:1; //fzc: 为1时标识该请求相关的工作全部结束了, 仅用在ngx_http_finalize_request
    unsigned                          logged:1; //fzc: 仅用在当前是子请求时,为1时表示当前子请求已经打印过log, 仅用在ngx_http_finalize_request中

    unsigned                          buffered:4; //fzc: 表示缓冲中是否有待发送内容的标志位

    unsigned                          main_filter_need_in_memory:1;
    unsigned                          filter_need_in_memory:1;
    unsigned                          filter_need_temporary:1;
    unsigned                          allow_ranges:1;
    unsigned                          single_range:1;

#if (NGX_STAT_STUB)
    unsigned                          stat_reading:1;
    unsigned                          stat_writing:1;
#endif

    /* used to parse HTTP headers */

    ngx_uint_t                        state; //fzc: parse http request line和request header时用到的状态机的state

    ngx_uint_t                        header_hash; //fzc: 用在ngx_http_parse_header_line中, 保存当前解析到的一项header的key的hash值
    ngx_uint_t                        lowcase_index; //fzc: 见ngx_http_process_request_headers, 以下两个都只是为了减少不必要的lowercase header key而设立.
    u_char                            lowcase_header[NGX_HTTP_LC_HEADER_LEN];

    u_char                           *header_name_start; //fzc: 用在ngx_http_parse_header_line中标记请求头的一个header项的起始位置
    u_char                           *header_name_end; //fzc: 同上, 但标记结束位置
    u_char                           *header_start; //fzc: header_name_start是header的key起始, 而header_start是header的value起始
    u_char                           *header_end; //fzc: 同上, 但标记结束位置

    /*
     * a memory that can be reused after parsing a request line
     * via ngx_http_ephemeral_t
     */

    u_char                           *uri_start;
    u_char                           *uri_end;
    u_char                           *uri_ext;
    u_char                           *args_start;
    u_char                           *request_start;
    u_char                           *request_end;
    u_char                           *method_end;
    u_char                           *schema_start;
    u_char                           *schema_end;
    u_char                           *host_start;
    u_char                           *host_end;
    u_char                           *port_start;
    u_char                           *port_end;

    unsigned                          http_minor:16;
    unsigned                          http_major:16;
};


typedef struct {
    ngx_http_posted_request_t         terminal_posted_request;
#if (NGX_HAVE_AIO_SENDFILE)
    u_char                            aio_preload;
#endif
} ngx_http_ephemeral_t;


extern ngx_http_header_t       ngx_http_headers_in[];
extern ngx_http_header_out_t   ngx_http_headers_out[];


#define ngx_http_set_connection_log(c, l)                                     \
                                                                              \
    c->log->file = l->file;                                                   \
    c->log->next = l->next;                                                   \
    if (!(c->log->log_level & NGX_LOG_DEBUG_CONNECTION)) {                    \
        c->log->log_level = l->log_level;                                     \
    }


#endif /* _NGX_HTTP_REQUEST_H_INCLUDED_ */
